package com.xbh.management.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xbh.common.web.core.Result;
import com.xbh.management.model.ManDeal;
import com.xbh.management.service.DealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: management-center
 * @description:
 * @author: 许宝华
 * @create: 2022-03-18 20:56
 */

@RestController
@RequestMapping(path = "/deal")
public class DealController {

    @Autowired
    private DealService dealService;

    @PostMapping("/page")
    public Result page(@RequestBody JSONObject params) {
        ManDeal deal = params.toJavaObject(ManDeal.class);
        int pageNum = params.getInteger("pageNum");
        int pageSize = params.getInteger("pageSize");
        LambdaQueryWrapper<ManDeal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ManDeal::getSalaryId, deal.getSalaryId());
        wrapper.orderByDesc(ManDeal::getCreateTime);
        Page<ManDeal> page = dealService.page(new Page<ManDeal>(pageNum, pageSize), wrapper);
        return Result.success(page);
    }
}
